home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Development Tools & Languages / Macintosh Common Lisp Related / interfaces / PInterface Translator / PInterfaces / Sound.p < prev    next >
Encoding:
Text File  |  1993-09-16  |  14.9 KB  |  456 lines  |  [TEXT/MPS ]

  1. {
  2. Created: Monday, January 28, 1991 at 6:55 PM
  3.     Sound.p
  4.     Pascal Interface to the Macintosh Libraries
  5.  
  6.         Copyright Apple Computer, Inc.    1986-1990
  7.         All rights reserved
  8. }
  9.  
  10.  
  11. {$IFC UNDEFINED UsingIncludes}
  12. {$SETC UsingIncludes := 0}
  13. {$ENDC}
  14.  
  15. {$IFC NOT UsingIncludes}
  16.     UNIT Sound;
  17.     INTERFACE
  18. {$ENDC}
  19.  
  20. {$IFC UNDEFINED UsingSound}
  21. {$SETC UsingSound := 1}
  22.  
  23. {$I+}
  24. {$SETC SoundIncludes := UsingIncludes}
  25. {$SETC UsingIncludes := 1}
  26. {$IFC UNDEFINED UsingTypes}
  27. {$I $$Shell(PInterfaces)Types.p}
  28. {$ENDC}
  29. {$IFC UNDEFINED UsingFiles}
  30. {$I $$Shell(PInterfaces)Files.p}
  31. {$ENDC}
  32. {$SETC UsingIncludes := SoundIncludes}
  33.  
  34. CONST
  35. swMode = -1;                                    { Sound Driver modes }
  36. ftMode = 1;
  37. ffMode = 0;
  38.  
  39. synthCodeRsrc = 'snth';                         { Resource types used by Sound Manager }
  40. soundListRsrc = 'snd ';
  41.  
  42. twelfthRootTwo = 1.05946309434;
  43. rate22khz = $56EE8BA3;                          { 22254.54545 in fixed-point }
  44. rate11khz = $2B7745D1;                          { 11127.27273 in fixed-point }
  45.  
  46. { synthesizer numbers for SndNewChannel }
  47. squareWaveSynth = 1;                            {square wave synthesizer}
  48. waveTableSynth = 3;                             {wave table synthesizer}
  49. sampledSynth = 5;                               {sampled sound synthesizer}
  50.  
  51. { old Sound Manager MACE synthesizer numbers }
  52. MACE3snthID = 11;
  53. MACE6snthID = 13;
  54.  
  55. { command numbers for SndDoCommand and SndDoImmediate }
  56. nullCmd = 0;
  57. initCmd = 1;
  58. freeCmd = 2;
  59. quietCmd = 3;
  60. flushCmd = 4;
  61. reInitCmd = 5;
  62.  
  63. waitCmd = 10;
  64. pauseCmd = 11;
  65. resumeCmd = 12;
  66. callBackCmd = 13;
  67. syncCmd = 14;
  68. emptyCmd = 15;
  69.  
  70. tickleCmd = 20;
  71. requestNextCmd = 21;
  72. howOftenCmd = 22;
  73. wakeUpCmd = 23;
  74. availableCmd = 24;
  75. versionCmd = 25;
  76. totalLoadCmd = 26;
  77. loadCmd = 27;
  78.  
  79. scaleCmd = 30;
  80. tempoCmd = 31;
  81.  
  82. freqDurationCmd = 40;
  83. restCmd = 41;
  84. freqCmd = 42;
  85. ampCmd = 43;
  86. timbreCmd = 44;
  87. getAmpCmd = 45;
  88.  
  89. waveTableCmd = 60;
  90. phaseCmd = 61;
  91.  
  92. soundCmd = 80;
  93. bufferCmd = 81;
  94. rateCmd = 82;
  95. continueCmd = 83;
  96. doubleBufferCmd = 84;
  97. getRateCmd = 85;
  98.  
  99. sizeCmd = 90;
  100. convertCmd = 91;
  101.  
  102. stdQLength = 128;
  103. dataOffsetFlag = $8000;
  104.  
  105. waveInitChannelMask = $07;
  106. waveInitChannel0 = $04;
  107. waveInitChannel1 = $05;
  108. waveInitChannel2 = $06;
  109. waveInitChannel3 = $07;
  110.  
  111. { channel initialization parameters }
  112. initPanMask = $0003;                            { mask for right/left pan values }
  113. initSRateMask = $0030;                          { mask for sample rate values }
  114. initStereoMask = $00C0;                         { mask for mono/stereo values }
  115. initCompMask = $FF00;                           { mask for compression IDs }
  116.  
  117. initChanLeft = $0002;                           { left stereo channel }
  118. initChanRight = $0003;                          { right stereo channel }
  119. initNoInterp = $0004;                           { no linear interpolation }
  120. initNoDrop = $0008;                             { no drop-sample conversion }
  121. initMono = $0080;                               { monophonic channel }
  122. initStereo = $00C0;                             { stereo channel }
  123. initMACE3 = $0300;                              { MACE 3:1 }
  124. initMACE6 = $0400;                              { MACE 6:1 }
  125.  
  126. initChan0 = $0004;                              { channel 0 - wave table only }
  127. initChan1 = $0005;                              { channel 1 - wave table only }
  128. initChan2 = $0006;                              { channel 2 - wave table only }
  129. initChan3 = $0007;                              { channel 3 - wave table only }
  130.  
  131. stdSH = $00;                                    { Standard sound header encode value }
  132. extSH = $FF;                                    { Extended sound header encode value }
  133. cmpSH = $FE;                                    { Compressed sound header encode value }
  134.  
  135. notCompressed = 0;                              { compression ID's }
  136. twoToOne = 1;
  137. eightToThree = 2;
  138. threeToOne = 3;
  139. sixToOne = 4;
  140.  
  141. outsideCmpSH = 0;                               { MACE constants }
  142. insideCmpSH = 1;
  143. aceSuccess = 0;
  144. aceMemFull = 1;
  145. aceNilBlock = 2;
  146. aceBadComp = 3;
  147. aceBadEncode = 4;
  148. aceBadDest = 5;
  149. aceBadCmd = 6;
  150. sixToOnePacketSize = 8;
  151. threeToOnePacketSize = 16;
  152. stateBlockSize = 64;
  153. leftOverBlockSize = 32;
  154.  
  155. firstSoundFormat = $0001;                       { general sound format }
  156. secondSoundFormat = $0002;                      { special sampled sound format (HyperCard) }
  157.  
  158. dbBufferReady = $00000001;                      { double buffer is filled }
  159. dbLastBuffer = $00000004;                       { last double buffer to play }
  160.  
  161. sysBeepDisable = $0000;                         { SysBeep() enable flags }
  162. sysBeepEnable = $0001;
  163.  
  164. unitTypeNoSelection = $FFFF;                    { unitTypes for AudioSelection.unitType }
  165. unitTypeSeconds = $0000;
  166.  
  167. TYPE
  168. {            Structures for Sound Driver            }
  169.  
  170.  
  171. FreeWave = PACKED ARRAY [0..30000] OF Byte;
  172.  
  173. FFSynthPtr = ^FFSynthRec;
  174. FFSynthRec = RECORD
  175.     mode: INTEGER;
  176.     count: Fixed;
  177.     waveBytes: FreeWave;
  178.     END;
  179.  
  180. Tone = RECORD
  181.     count: INTEGER;
  182.     amplitude: INTEGER;
  183.     duration: INTEGER;
  184.     END;
  185.  
  186.  
  187. Tones = ARRAY [0..5000] OF Tone;
  188.  
  189. SWSynthPtr = ^SWSynthRec;
  190. SWSynthRec = RECORD
  191.     mode: INTEGER;
  192.     triplets: Tones;
  193.     END;
  194.  
  195.  
  196. Wave = PACKED ARRAY [0..255] OF Byte;
  197. WavePtr = ^Wave;
  198.  
  199. FTSndRecPtr = ^FTSoundRec;
  200. FTSoundRec = RECORD
  201.     duration: INTEGER;
  202.     sound1Rate: Fixed;
  203.     sound1Phase: LONGINT;
  204.     sound2Rate: Fixed;
  205.     sound2Phase: LONGINT;
  206.     sound3Rate: Fixed;
  207.     sound3Phase: LONGINT;
  208.     sound4Rate: Fixed;
  209.     sound4Phase: LONGINT;
  210.     sound1Wave: WavePtr;
  211.     sound2Wave: WavePtr;
  212.     sound3Wave: WavePtr;
  213.     sound4Wave: WavePtr;
  214.     END;
  215.  
  216. FTSynthPtr = ^FTSynthRec;
  217. FTSynthRec = RECORD
  218.     mode: INTEGER;
  219.     sndRec: FTSndRecPtr;
  220.     END;
  221.  
  222. {            Structures for Sound Manager            }
  223.  
  224. SndCommand = PACKED RECORD
  225.     cmd: INTEGER;
  226.     param1: INTEGER;
  227.     param2: LONGINT;
  228.     END;
  229.  
  230.  
  231. Time = LONGINT;                                 { in half milliseconds }
  232.  
  233.  
  234.  
  235. SndChannelPtr = ^SndChannel;
  236. SndChannel = PACKED RECORD
  237.     nextChan: SndChannelPtr;
  238.     firstMod: Ptr;                              { reserved for the Sound Manager }
  239.     callBack: ProcPtr;
  240.     userInfo: LONGINT;
  241.     wait: Time;                                 { The following is for internal Sound Manager use only.}
  242.     cmdInProgress: SndCommand;
  243.     flags: INTEGER;
  244.     qLength: INTEGER;
  245.     qHead: INTEGER;                             { next spot to read or -1 if empty }
  246.     qTail: INTEGER;                             { next spot to write = qHead if full }
  247.     queue: ARRAY [0..stdQLength - 1] OF SndCommand;
  248.     END;
  249.  
  250. { MACE structures }
  251. StateBlockPtr = ^StateBlock;
  252. StateBlock = RECORD
  253.     stateVar: ARRAY [0..stateBlockSize - 1] OF INTEGER;
  254.     END;
  255.  
  256. LeftOverBlockPtr = ^LeftOverBlock;
  257. LeftOverBlock = RECORD
  258.     count: LONGINT;
  259.     sampleArea: ARRAY [0..leftOverBlockSize - 1] OF Byte;
  260.     END;
  261.  
  262. ModRef = RECORD
  263.     modNumber: INTEGER;
  264.     modInit: LONGINT;
  265.     END;
  266.  
  267. SndListPtr = ^SndListResource;
  268. SndListResource = RECORD
  269.     format: INTEGER;
  270.     numModifiers: INTEGER;
  271.     modifierPart: ARRAY [0..0] OF ModRef;       {This is a variable length array}
  272.     numCommands: INTEGER;
  273.     commandPart: ARRAY [0..0] OF SndCommand;    {This is a variable length array}
  274.     dataPart: PACKED ARRAY [0..0] OF Byte;      {This is a variable length array}
  275.     END;
  276.  
  277. SoundHeaderPtr = ^SoundHeader;
  278. SoundHeader = PACKED RECORD
  279.     samplePtr: Ptr;                             { if NIL then samples are in sampleArea }
  280.     length: LONGINT;                            { length of sound in bytes }
  281.     sampleRate: Fixed;                          { sample rate for this sound }
  282.     loopStart: LONGINT;                         { start of looping portion }
  283.     loopEnd: LONGINT;                           { end of looping portion }
  284.     encode: Byte;                               { header encoding }
  285.     baseFrequency: Byte;                        { baseFrequency value }
  286.     sampleArea: ARRAY [0..0] OF Byte;
  287.     END;
  288.  
  289.  
  290. CmpSoundHeaderPtr = ^CmpSoundHeader;
  291. CmpSoundHeader = PACKED RECORD
  292.     samplePtr: Ptr;                             { if nil then samples are in sample area }
  293.     numChannels: LONGINT;                       { number of channels i.e. mono = 1 }
  294.     sampleRate: Fixed;                          { sample rate in Apples Fixed point representation }
  295.     loopStart: LONGINT;                         { loopStart of sound before compression }
  296.     loopEnd: LONGINT;                           { loopEnd of sound before compression }
  297.     encode: Byte;                               { data structure used , stdSH, extSH, or cmpSH }
  298.     baseFrequency: Byte;                        { same meaning as regular SoundHeader }
  299.     numFrames: LONGINT;                         { length in frames ( packetFrames or sampleFrames ) }
  300.     AIFFSampleRate: extended;                   { IEEE sample rate }
  301.     markerChunk: Ptr;                           { sync track }
  302.     futureUse1: Ptr;                            { reserved by Apple }
  303.     futureUse2: Ptr;                            { reserved by Apple }
  304.     stateVars: StateBlockPtr;                   { pointer to State Block }
  305.     leftOverSamples: LeftOverBlockPtr;          { used to save truncated samples between compression calls }
  306.     compressionID: INTEGER;                     { 0 means no compression, non zero means compressionID }
  307.     packetSize: INTEGER;                        { number of bits in compressed sample packet }
  308.     snthID: INTEGER;                            { resource ID of Sound Manager snth that contains NRT C/E }
  309.     sampleSize: INTEGER;                        { number of bits in non-compressed sample }
  310.     sampleArea: ARRAY [0..0] OF Byte;           { space for when samples follow directly }
  311.     END;
  312.  
  313. ExtSoundHeaderPtr = ^ExtSoundHeader;
  314. ExtSoundHeader = PACKED RECORD
  315.     samplePtr: Ptr;                             { if nil then samples are in sample area }
  316.     numChannels: LONGINT;                       { number of channels,  ie mono = 1 }
  317.     sampleRate: Fixed;                          { sample rate in Apples Fixed point representation }
  318.     loopStart: LONGINT;                         { same meaning as regular SoundHeader }
  319.     loopEnd: LONGINT;                           { same meaning as regular SoundHeader }
  320.     encode: Byte;                               { data structure used , stdSH, extSH, or cmpSH }
  321.     baseFrequency: Byte;                        { same meaning as regular SoundHeader }
  322.     numFrames: LONGINT;                         { length in total number of frames }
  323.     AIFFSampleRate: extended;                   { IEEE sample rate }
  324.     markerChunk: Ptr;                           { sync track }
  325.     instrumentChunks: Ptr;                      { AIFF instrument chunks }
  326.     AESRecording: Ptr;
  327.     sampleSize: INTEGER;                        { number of bits in sample }
  328.     futureUse1: INTEGER;                        { reserved by Apple }
  329.     futureUse2: LONGINT;                        { reserved by Apple }
  330.     futureUse3: LONGINT;                        { reserved by Apple }
  331.     futureUse4: LONGINT;                        { reserved by Apple }
  332.     sampleArea: ARRAY [0..0] OF Byte;           { space for when samples follow directly }
  333.     END;
  334.  
  335. ConversionBlockPtr = ^ConversionBlock;
  336. ConversionBlock = RECORD
  337.     destination: INTEGER;
  338.     unused: INTEGER;
  339.     inputPtr: CmpSoundHeaderPtr;
  340.     outputPtr: CmpSoundHeaderPtr;
  341.     END;
  342.  
  343. SMStatusPtr = ^SMStatus;
  344. SMStatus = PACKED RECORD
  345.     smMaxCPULoad: INTEGER;
  346.     smNumChannels: INTEGER;
  347.     smCurCPULoad: INTEGER;
  348.     END;
  349.  
  350. SCStatusPtr = ^SCStatus;
  351. SCStatus = RECORD
  352.     scStartTime: Fixed;
  353.     scEndTime: Fixed;
  354.     scCurrentTime: Fixed;
  355.     scChannelBusy: BOOLEAN;
  356.     scChannelDisposed: BOOLEAN;
  357.     scChannelPaused: BOOLEAN;
  358.     scUnused: BOOLEAN;
  359.     scChannelAttributes: LONGINT;
  360.     scCPULoad: LONGINT;
  361.     END;
  362.  
  363. AudioSelectionPtr = ^AudioSelection;
  364. AudioSelection = PACKED RECORD
  365.     unitType: LONGINT;
  366.     selStart: Fixed;
  367.     selEnd: Fixed;
  368.     END;
  369.  
  370. SndDoubleBufferPtr = ^SndDoubleBuffer;
  371. SndDoubleBuffer = PACKED RECORD
  372.     dbNumFrames: LONGINT;
  373.     dbFlags: LONGINT;
  374.     dbUserInfo: ARRAY [0..1] OF LONGINT;
  375.     dbSoundData: PACKED ARRAY [0..0] OF Byte;
  376.     END;
  377.  
  378. SndDoubleBufferHeaderPtr = ^SndDoubleBufferHeader;
  379. SndDoubleBufferHeader = PACKED RECORD
  380.     dbhNumChannels: INTEGER;
  381.     dbhSampleSize: INTEGER;
  382.     dbhCompressionID: INTEGER;
  383.     dbhPacketSize: INTEGER;
  384.     dbhSampleRate: Fixed;
  385.     dbhBufferPtr: ARRAY [0..1] OF SndDoubleBufferPtr;
  386.     dbhDoubleBack: ProcPtr;
  387.     END;
  388.  
  389.  
  390. FUNCTION SndDoCommand(chan: SndChannelPtr;cmd: SndCommand;noWait: BOOLEAN): OSErr;
  391.     INLINE $A803;
  392. FUNCTION SndDoImmediate(chan: SndChannelPtr;cmd: SndCommand): OSErr;
  393.     INLINE $A804;
  394. FUNCTION SndNewChannel(VAR chan: SndChannelPtr;synth: INTEGER;init: LONGINT;
  395.     userRoutine: ProcPtr): OSErr;
  396.     INLINE $A807;
  397. FUNCTION SndDisposeChannel(chan: SndChannelPtr;quietNow: BOOLEAN): OSErr;
  398.     INLINE $A801;
  399. FUNCTION SndPlay(chan: SndChannelPtr;sndHdl: Handle;async: BOOLEAN): OSErr;
  400.     INLINE $A805;
  401. FUNCTION SndAddModifier(chan: SndChannelPtr;modifier: ProcPtr;id: INTEGER;
  402.     init: LONGINT): OSErr;
  403.     INLINE $A802;
  404. FUNCTION SndControl(id: INTEGER;VAR cmd: SndCommand): OSErr;
  405.     INLINE $A806;
  406.  
  407. PROCEDURE SetSoundVol(level: INTEGER);
  408. PROCEDURE GetSoundVol(VAR level: INTEGER);
  409. PROCEDURE StartSound(synthRec: Ptr;numBytes: LONGINT;completionRtn: ProcPtr);
  410. PROCEDURE StopSound;
  411. FUNCTION SoundDone: BOOLEAN;
  412.  
  413. FUNCTION SndSoundManagerVersion: NumVersion;
  414.     INLINE $203C,$000C,$0008,$A800;
  415. FUNCTION SndStartFilePlay(chan: SndChannelPtr;fRefNum: INTEGER;resNum: INTEGER;
  416.     bufferSize: LONGINT;theBuffer: Ptr;theSelection: AudioSelectionPtr;theCompletion: ProcPtr;
  417.     async: BOOLEAN): OSErr;
  418.     INLINE $203C,$0D00,$0008,$A800;
  419. FUNCTION SndPauseFilePlay(chan: SndChannelPtr): OSErr;
  420.     INLINE $203C,$0204,$0008,$A800;
  421. FUNCTION SndStopFilePlay(chan: SndChannelPtr;async: BOOLEAN): OSErr;
  422.     INLINE $203C,$0308,$0008,$A800;
  423. FUNCTION SndChannelStatus(chan: SndChannelPtr;theLength: INTEGER;theStatus: SCStatusPtr): OSErr;
  424.     INLINE $203C,$0010,$0008,$A800;
  425. FUNCTION SndManagerStatus(theLength: INTEGER;theStatus: SMStatusPtr): OSErr;
  426.     INLINE $203C,$0014,$0008,$A800;
  427. PROCEDURE SndGetSysBeepState(VAR sysBeepState: INTEGER);
  428.     INLINE $203C,$0018,$0008,$A800;
  429. FUNCTION SndSetSysBeepState(sysBeepState: INTEGER): OSErr;
  430.     INLINE $203C,$001C,$0008,$A800;
  431. FUNCTION SndPlayDoubleBuffer(chan: SndChannelPtr;theParams: SndDoubleBufferHeaderPtr): OSErr;
  432.     INLINE $203C,$0020,$0008,$A800;
  433.  
  434. FUNCTION MACEVersion: NumVersion;
  435.     INLINE $203C,$0000,$0010,$A800;
  436. PROCEDURE Comp3to1(inBuffer: Ptr;outBuffer: Ptr;cnt: LONGINT;inState: Ptr;
  437.     outState: Ptr;numChannels: LONGINT;whichChannel: LONGINT);
  438.     INLINE $203C,$0004,$0010,$A800;
  439. PROCEDURE Exp1to3(inBuffer: Ptr;outBuffer: Ptr;cnt: LONGINT;inState: Ptr;
  440.     outState: Ptr;numChannels: LONGINT;whichChannel: LONGINT);
  441.     INLINE $203C,$0008,$0010,$A800;
  442. PROCEDURE Comp6to1(inBuffer: Ptr;outBuffer: Ptr;cnt: LONGINT;inState: Ptr;
  443.     outState: Ptr;numChannels: LONGINT;whichChannel: LONGINT);
  444.     INLINE $203C,$000C,$0010,$A800;
  445. PROCEDURE Exp1to6(inBuffer: Ptr;outBuffer: Ptr;cnt: LONGINT;inState: Ptr;
  446.     outState: Ptr;numChannels: LONGINT;whichChannel: LONGINT);
  447.     INLINE $203C,$0010,$0010,$A800;
  448.  
  449.  
  450. {$ENDC}    { UsingSound }
  451.  
  452. {$IFC NOT UsingIncludes}
  453.     END.
  454. {$ENDC}
  455.  
  456.